package com.by.controller;

import com.by.bean.Organize;
import com.by.bean.Role;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.common.group.ISave;
import com.by.service.OrganizeService;
import com.by.service.RoleService;
import com.by.service.impl.RoleServiceImpl;
import io.swagger.annotations.Api;


import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author HY
 * @version 1.0
 * @description
 * @date 2025/2/17
 * @since JDK21
 */
@RestController
@RequestMapping("/api/role")
@Api(tags = "角色管理")
public class RoleController extends BaseController {

    @Autowired
    RoleService roleService;


    @PostMapping("/save")
    @ApiOperation("新增角色")
    public ResultBean saveDepartment(@Validated(ISave.class) @RequestBody Role role) {
        int save = roleService.save(role);

        return save!=0? success("新增角色成功"):fail("新增角色失败");
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除角色")
    public ResultBean deleteDepartment(@PathVariable int id) {
        int delete = roleService.delete(id);
        return delete!=0?success("删除角色成功"):fail("删除角色失败");
    }
    @PutMapping("/update")
    @ApiOperation("修改角色")
    public ResultBean updateDepartment(@Validated(ISave.class) @RequestBody Role role) {
        int update = roleService.update(role);
        return update!=0?success("修改角色成功"):fail("修改角色失败");
    }

    @GetMapping("/query")
    @ApiOperation("查询角色")
    public ResultBean query(){
        List<Role> query = roleService.query();
        return query!=null?success("查询角色成功",query):fail("查询角色失败");
    }

    @GetMapping("/queryByName/{name}/{status}")
    @ApiOperation("根据角色名称查询角色")
    public ResultBean queryByName(@PathVariable("name") String name , @PathVariable("status") int status){
        List<Role> queryByName = roleService.queryByName(name,status);
        return queryByName!=null?success("查询角色成功",queryByName):fail("查询角色失败");
    }
}
